#include "umsdata.h"
#include <QtXml>

UMSData::UMSData()
{
	
}


QStringList UMSData::coordinates(const QDomElement &pelem)
{
	QStringList slist;
	
	QDomElement elem = pelem.firstChildElement("coordinate");
	//qDebug() << Q_FUNC_INFO << elem.isNull();
	while(!elem.isNull()){
		slist << elem.attribute("name");		
		slist << coordinates(elem);
		//qDebug() << slist; 
		elem = elem.nextSiblingElement("coordinate");
	}
		
	QStringList rlist;
	foreach(QString s,slist){
		if(rlist.indexOf(s)<0) rlist <<s;
	}	
	return rlist;
}

void UMSData::setVector(const QDomElement &elem)
{
	_vector = elem;
}

QStringList UMSData::values(const QString &crdname)
{
	return nodeValues(crdname,&_vector);
}

QStringList UMSData::nodeValues(const QString &crdname,QDomElement *pelem)
{
	QStringList vlist;
	if(!pelem || pelem->isNull()) return vlist;
	QDomElement elem = pelem->firstChildElement("coordinate");
	while(!elem.isNull()){
		if(elem.attribute("name")==crdname){
			QString text = elem.text();
			if(text.left(1)=="\n") text = text.right(text.length()-1);
			vlist << text;
		}
		vlist << nodeValues(crdname,&elem);
		elem = elem.nextSiblingElement("coordinate");
	}
	return vlist;
}


QString UMSData::uin()
{
	return _vector.attribute("id");
}


